package a2022.a20221011;

import java.util.*;

/**
 * @author lenovo
 * @date 2022/10/11
 */
public class b {
    static int n = 100;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<Integer, List<String>> map = new HashMap<Integer, List<String>>();
        int time = scanner.nextInt();
        int num = 0;
        for (int i = 0; i < time; i++) {
            n = scanner.nextInt();
            num = Math.max(num, n);
            String m = scanner.next();
            List<String> list = new ArrayList<>();
            list.add(m);
            int len = 1;
            for (int j = 0; j < n; j++) {
                String s = scanner.next();
                list.add(s);
                len = Math.max(len, (s.length() + 1-s.replaceAll(",", "").length()));
            }
            list.set(0, list.get(0) + len);
            map.put(i, list);
        }
        num++;
        List<String> ss = new ArrayList<>(Collections.nCopies(num, ""));
        for (int i = 0; i < time; i++) {
            List<String> list = map.get(i);
            for (int j  = 0; j < num; j++) {
                int x = Integer.parseInt(list.get(0).substring(list.get(0).length() - 1));
                if (list.size() > j) {
                    int y = (list.get(j).length() + 1-list.get(j).replaceAll(",", "").length());
                    ss.set(j, ss.get(j) + (j > 0 ?
                            list.get(j) + (y != x ?
                                    (i != (time - 1) ?
                                            String.join("", Collections.nCopies(x - y + 1, ","))
                                            :
                                            String.join("", Collections.nCopies(x - y, ","))) :
                                    (i != (time - 1) ? "," : ""))
                            :
                            list.get(0).substring(0, 1) + (i != (time - 1) ?
                                    String.join("", Collections.nCopies(x, ",")) :
                                    String.join("", Collections.nCopies(x - 1, ",")))));
                } else {
                    ss.set(j, ss.get(j) + (i != (time - 1) ?
                            String.join("", Collections.nCopies( x, ",")) :
                            String.join("", Collections.nCopies(x > 2 ? x - 2 : 0, ","))));
                }
            }
        }
        for (int i = 0; i < ss.size(); i++) {
            System.out.println(ss.get(i));
        }
    }
}
